package view;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import control.Supervisorio;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class NewProjectWindow extends javax.swing.JFrame {
	private JPanel jPanel1;
	private JLabel lblDescricao;
	private JScrollPane jScrollPane1;
	private JTextArea txtDescricao;
	private JButton btnCancel;
	private JButton btnCriar;
	private JSeparator jSeparator1;
	private JTextField txtFabrica;
	private JTextField txtProjeto;
	private JLabel lblFabrica;
	private JLabel lblProject;
	private JPanel jPanel2;

	private Supervisorio supervisorio;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				NewProjectWindow inst = new NewProjectWindow();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public NewProjectWindow() {
		super();
		initGUI();
		supervisorio = Supervisorio.getInstance();
	}

	private void initGUI() {
		try {
			BorderLayout thisLayout = new BorderLayout();
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("i2M - Novo Projeto");
			getContentPane().setLayout(thisLayout);
			{
				jPanel2 = new JPanel();
				getContentPane().add(jPanel2, BorderLayout.SOUTH);
				jPanel2.setPreferredSize(new java.awt.Dimension(392, 33));
				jPanel2.setLayout(null);
				{
					btnCriar = new JButton();
					jPanel2.add(btnCriar);
					btnCriar.setText("Criar");
					btnCriar.setLayout(null);
					btnCriar.setBounds(89, 4, 93, 21);
					btnCriar.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent e) {
							btnCreateMouseClicked(e);
						}

					});
				}
				{
					btnCancel = new JButton();
					jPanel2.add(btnCancel);
					btnCancel.setText("Cancelar");
					btnCancel.setLayout(null);
					btnCancel.setBounds(210, 4, 94, 21);
					btnCancel.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent e) {
							btnCancelMouseClicked(e);
						}
					});
				}
			}
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(null);
				{
					lblProject = new JLabel();
					jPanel1.add(lblProject);
					lblProject.setText("Nome do Projeto:");
					lblProject.setLayout(null);
					lblProject.setBounds(12, 12, 117, 14);
				}
				{
					lblFabrica = new JLabel();
					jPanel1.add(lblFabrica);
					lblFabrica.setText("Nome da Fabrica:");
					lblFabrica.setLayout(null);
					lblFabrica.setBounds(12, 39, 112, 14);
				}
				{
					lblDescricao = new JLabel();
					jPanel1.add(lblDescricao);
					lblDescricao.setText("Descrição: ");
					lblDescricao.setLayout(null);
					lblDescricao.setBounds(12, 65, 124, 14);
				}
				{
					txtProjeto = new JTextField();
					jPanel1.add(txtProjeto);
					txtProjeto.setBounds(136, 9, 237, 21);
				}
				{
					txtFabrica = new JTextField();
					jPanel1.add(txtFabrica);
					txtFabrica.setBounds(136, 36, 237, 21);
				}
				{
					jSeparator1 = new JSeparator();
					jPanel1.add(jSeparator1);
					jSeparator1.setLayout(null);
					jSeparator1.setBounds(12, 112, 361, 10);
				}
				{
					jScrollPane1 = new JScrollPane();
					jPanel1.add(jScrollPane1);
					jScrollPane1.setBounds(136, 63, 237, 44);
					{
						txtDescricao = new JTextArea();
						jScrollPane1.setViewportView(txtDescricao);
					}
				}
			}
			pack();
			this.setSize(400, 186);
			this.setLocationRelativeTo(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void btnCancelMouseClicked(MouseEvent e) {
		this.dispose();
	}

	private void btnCreateMouseClicked(MouseEvent e) {
		String nomeProjeto = txtProjeto.getText();
		String nomeFabrica = txtFabrica.getText();
		String descricao = txtDescricao.getText();

		if (nomeProjeto.trim().equals("")) {
			JOptionPane.showMessageDialog(null,
					"Insira um nome para o projeto!");
			return;
		}
		supervisorio.createProject(nomeProjeto, nomeFabrica, descricao);
		this.dispose();
	}
}
